import {onMounted, onUnmounted, ref} from "vue";
export  function useScroll(dom:any) {
    const isReachBottom = ref(false);//布尔值是否到达底部
    const scrollListenerHandler = () => {
        const clientHeight: any = dom.clientHeight;
        const scrollTop: any = dom.scrollTop;
        const scrollHeight: any = dom.scrollHeight;
        //如果滚动到了底部
        // console.log("5555555555555555555555", clientHeight, scrollTop, scrollHeight, clientHeight + scrollTop)
        if (scrollHeight <= clientHeight + scrollTop) {
            isReachBottom.value = true;
            console.log("已经滚动到底部");
            // console.log('66666666666666666666666',isReachBottom.value)
       
        }
        return isReachBottom.value
    }
    // onMounted(() => {
    //     window.addEventListener('scroll', scrollListenerHandler);
    // })
    // onUnmounted(() => {
    //     window.removeEventListener('scroll', scrollListenerHandler);
    // })
    return { isReachBottom,scrollListenerHandler };
}
export function mydebounce (fun:Function, time:number):Function{
    let timer: any;
    console.log("执行了封装函数");
    return function(this:any,...args:any) {
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(() => {
            fun.apply(this, args);
        }, time)
    }
}